﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.XtraGrid.Views.Grid;

namespace QuanLyKho.BanHang
{
    public partial class DanhSachHangTrongKho : UserControl
    {
        public DanhSachHangTrongKho()
        {
            InitializeComponent();
            LoadData();
        }

        public void LoadData()
        {
            var table = DataAll.SelectAll("[HangTrongKho]",
                "TenKho, SUM(SoLuong) AS 'TongSoLuong'", " GROUP BY  TenKho HAVING SUM(SoLuong) > 0");
            gridKho.DataSource = table;
            SetPropertiesGrid();
        }

        public void SetPropertiesGrid()
        {
            //gvChiaHang.BestFitColumns();
            gvKho.OptionsBehavior.Editable = false;
            gvKho.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            gvKho.OptionsSelection.EnableAppearanceFocusedCell = false;
            gvKho.OptionsSelection.MultiSelect = true;
            gvKho.OptionsView.ShowGroupPanel = false;
            gvKho.OptionsView.ColumnAutoWidth = true;
            gvKho.OptionsView.ShowFooter = true;
            gvKho.OptionsFind.AlwaysVisible = true;
            gvKho.Columns["ID"].Visible = false;
        }

        private void gvKho_DoubleClick(object sender, EventArgs e)
        {
            if (gvKho.FocusedRowHandle >= 0)
            {
                DanhSachSPCuaCuaHang.CuaHang = gvKho.GetDataRow(gvKho.FocusedRowHandle)["TenKho"].ToString();
                DanhSachSPCuaCuaHang.Loai = false;
                var themsp = new DanhSachSPCuaCuaHang();
                themsp.ShowDialog();
                LoadData();
                DanhSachSPCuaCuaHang.CuaHang = "0";
            }
        }

        private void bntChuyenKho_Click(object sender, EventArgs e)
        {
            var chuyenkho = new ThemChuyenKho();
            chuyenkho.ShowDialog();
            LoadData();
        }
    }
}
